package com.threeox.httplibrary.callback;

import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 *
 * @ClassName: Callback
 *
 * @Description: Todo(返回对象的抽象类)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2016/12/21 11:33
 *
 * @version 1.0
 */
public abstract class Callback<T> {

    /**
     * UI Thread
     *
     * @param request
     */
    public void onBefore(Request request, int id, String url) {
    }

    /**
     * UI Thread
     *
     * @param
     */
    public void onAfter(int id, String url) {
    }

    /**
     * UI线程 比如下载进度加载
     *
     * @param progress
     */
    public void inProgress(float progress, long total , int id, String url) {

    }

    /**
     * 如果你在parseNetworkResponse解析响应代码,你应该让这个方法返回true。
     *
     * @param response
     * @return
     */
    public boolean validateReponse(Response response, int id, String url) {
        return response.isSuccessful();
    }

    /**
     * 线程池线程
     *
     * @param response
     */
    public abstract T parseNetworkResponse(Response response, int id, String url) throws Exception;

    public abstract void onError(Call call, Exception e, int id, String url);

    public abstract void onResponse(T response, int id, String url);

    public static Callback CALLBACK_DEFAULT = new Callback() {

        @Override
        public Object parseNetworkResponse(Response response, int id, String url) throws Exception {
            return null;
        }

        @Override
        public void onError(Call call, Exception e, int id, String url) {

        }

        @Override
        public void onResponse(Object response, int id, String url) {

        }
    };

}